v->arch.hvm_svm.vmcb->cr2 = v->arch.hvm_svm.cpu_cr2 = cr2;
}
+static int svm_injection_pending(struct vcpu *v)
+{
+ struct vmcb_struct *vmcb = v->arch.hvm_svm.vmcb;
+ return (vmcb->vintr.fields.irq || vmcb->exitintinfo.fields.v);
+}
+
int start_svm(void)
{
u32 eax, ecx, edx;
hvm_funcs.init_ap_context = svm_init_ap_context;
hvm_funcs.init_hypercall_page = svm_init_hypercall_page;
+ hvm_funcs.injection_pending = svm_injection_pending;
+
hvm_enable();
return 1;
/* VMX doesn't have a V_TPR field */
}
+static int vmx_injection_pending(struct vcpu *v)
+{
+ unsigned int idtv_info_field;
+
+ ASSERT(v == current);
+
+ idtv_info_field = __vmread(IDT_VECTORING_INFO_FIELD);
+
+ return (v->arch.hvm_vmx.vector_injected ||
+ (idtv_info_field & INTR_INFO_VALID_MASK));
+}
+
/* Setup HVM interfaces */
static void vmx_setup_hvm_funcs(void)
{
hvm_funcs.init_ap_context = vmx_init_ap_context;
hvm_funcs.init_hypercall_page = vmx_init_hypercall_page;
+
+ hvm_funcs.injection_pending = vmx_injection_pending;
}
int start_vmx(void)
goto not_a_shadow_fault;
if ( is_hvm_domain(d) )
+ {
+ /*
+ * If we are in the middle of injecting an exception or interrupt then
+ * we should not emulate: it is not the instruction at %eip that caused
+ * the fault. Furthermore it is almost certainly the case the handler
+ * stack is currently considered to be a page table, so we should
+ * unshadow the faulting page before exiting.
+ */
+ if ( hvm_injection_pending(v) )
+ {
+ gdprintk(XENLOG_DEBUG, "write to pagetable during event "
+ "injection: cr2=%#lx, mfn=%#lx\n",
+ va, mfn_x(gmfn));
+ sh_remove_shadows(v, gmfn, 0 /* thorough */, 1 /* must succeed */);
+ goto done;
+ }
+
hvm_store_cpu_guest_regs(v, regs, NULL);
+ }
+
SHADOW_PRINTK("emulate: eip=%#lx esp=%#lx\n",
(unsigned long)regs->eip, (unsigned long)regs->esp);
- /* Check whether this looks like a stack operation. */
+ /*
+ * Check whether this looks like a stack operation.
+ * If so, forcibly unshadow and return.
+ */
if ( (va & PAGE_MASK) == (regs->esp & PAGE_MASK) )
{
- /* Forcibly unshadow and return. It's important to do this before
- * we emulate: if the faulting stack operation was the guest handling
- * an interrupt, then
- * (a) the instruction at %eip is irrelevant; and
- * (b) we might inject some other fault and mask the real one */
gdprintk(XENLOG_DEBUG, "guest stack is on a shadowed frame: "
"%%esp=%#lx, cr2=%#lx, mfn=%#lx\n",
(unsigned long)regs->esp, va, mfn_x(gmfn));
int vcpuid, int trampoline_vector);
void (*init_hypercall_page)(struct domain *d, void *hypercall_page);
+
+ int (*injection_pending)(struct vcpu *v);
};
extern struct hvm_function_table hvm_funcs;
int hvm_bringup_ap(int vcpuid, int trampoline_vector);
+static inline int hvm_injection_pending(struct vcpu *v)
+{
+ return hvm_funcs.injection_pending(v);
+}
+
#endif /* __ASM_X86_HVM_HVM_H__ */